<!--
 * @Description: 商家任务审核列表
 * @Author: liyujie
 * @Date: 2021/05/10
 * @Last Modified by: liyujie
 * @Last Modified time: 2021/05/10
-->
<template>
    <div class="wrapper">
        <div class="content-wrapper">
            <!-- header -->
            <div class="header">
                <div class="header-title">
                    商家任务审核
                </div>
            </div>
            <!-- /header -->
            <!-- 筛选-->
            <div class="filter-view">
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        任务信息
                    </p>
                    <el-input
                        placeholder="搜索任务标题/ID"
                        v-model="filterData.task_keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 240px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        公司信息
                    </p>
                    <el-input
                        placeholder="搜索公司ID/名称"
                        v-model="filterData.company_keyword"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 240px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        审核状态
                    </p>
                    <el-select
                        v-model="filterData.verify"
                        filterable
                        placeholder="全部"
                        size="medium"
                        @change="getTableData(1)"
                    >
                        <el-option
                            v-for="item in statusList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value"
                        />
                    </el-select>
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        审核人
                    </p>
                    <el-input
                        placeholder="搜索审核人"
                        v-model="filterData.admin_true_name"
                        suffix-icon="el-icon-search"
                        clearable
                        size="medium"
                        style="width: 240px"
                        @keydown.enter.native="getTableData(1)"
                    />
                </div>
                <div class="header-new-box">
                    <p class="header-new-box-title">
                        提交时间
                    </p>
                    <el-date-picker
                        v-model="dateTimeRange"
                        type="datetimerange"
                        range-separator="-"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
                        size="medium"
                        style="width: 360px"
                        value-format="timestamp"
                    />
                </div>
                <div class="header-new-box">
                    <el-button
                        type="primary"
                        size="small"
                        @click="getTableData(1)"
                    >
                        查询
                    </el-button>
                </div>
            </div>
            <!--筛选-->
            <!-- table -->
            <div class="table-wrapper">
                <el-table
                    :data="tableData"
                    height="100%"
                    style="width: 100%;"
                    ref="table"
                    class="data-table"
                    :cell-style="{height: '106px'}"
                    v-loading="tableLoading"
                >
                    <el-table-column
                        label="序号"
                        align="center"
                        width="50"
                        type="index"
                        fixed="left"
                    />
                    <el-table-column
                        label="任务信息"
                        width="200"
                        fixed="left"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="cell-title">{{ scope.row.task_title }}</div>
                            <div class="cell-tips">任务ID：{{ scope.row.task_no }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="公司信息"
                        width="200"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="cell-title">{{ scope.row.company_name }}</div>
                            <div class="cell-tips">公司ID：{{ scope.row.hire_no }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="任务简介"
                        width="180"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="cell-content">{{ scope.row.task_intro ? scope.row.task_intro : '--' }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="考核标准"
                        width="180"
                        :formatter="emptyFormatter"
                    >
                        <template slot-scope="scope">
                            <div class="cell-content">{{ scope.row.task_standard }}</div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="任务时间"
                        align="left"
                        :formatter="emptyFormatter"
                        min-width="160"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.start_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }} -
                            {{ scope.row.end_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="提交时间"
                        align="left"
                        :formatter="emptyFormatter"
                        min-width="160"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.create_time * 1000 | dateFormatter('yyyy/MM/dd HH:mm:ss') }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="all_count"
                        label="任务总数"
                        show-overflow-tooltip
                        align="center"
                    />
                    <el-table-column
                        prop="task_price"
                        label="单任务酬劳"
                        show-overflow-tooltip
                        align="center"
                        width="110"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.task_price }} 元/个
                        </template>
                    </el-table-column>
                    <el-table-column
                        label="审核状态"
                        align="center"
                        width="150"
                    >
                        <template slot-scope="scope">
                            <div class="status-wrapper">
                                <div
                                    :class="['status-dot', scope.row.verify === 1 ? 'warning' : (scope.row.verify === 2 ? 'success' : scope.row.verify === 0 ? 'normal' : 'danger')]"/>
                                <div>{{ scope.row.verify | statusFilter }}</div>
                                <el-button
                                    type="text"
                                    style="margin-left: 6px; font-size: 12px"
                                    v-if="scope.row.verify === -1"
                                    @click="showReason(scope.row)"
                                >
                                    (查看原因)
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="verify_admin_true_name"
                        label="审核人"
                        show-overflow-tooltip
                        align="center"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        label="操作"
                        align="left"
                        width="180"
                        fixed="right"
                    >
                        <template slot-scope="scope">
                            <div class="option-btn-group">
                                <el-button
                                    type="text"
                                    @click="handleRoute('shopTaskVerifyDetail', {task_no: scope.row.task_no})"
                                >
                                    {{ scope.row.verify === 1 ? '审核' : '查看' }}
                                </el-button>
                                <el-button
                                    type="text"
                                    :disabled="scope.row.verify !== 1"
                                    @click="showVerifyDialog(2, scope.row)"
                                >
                                    通过
                                </el-button>
                                <el-button
                                    type="text"
                                    :disabled="scope.row.verify !== 1"
                                    @click="showVerifyDialog(-1, scope.row)"
                                >
                                    不通过
                                </el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <!-- /table -->
            <!-- /分页 -->
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    layout="total, prev, pager, next, jumper"
                    background
                    :current-page.sync="page.now_page"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
        <!-- 审核驳回 -->
        <reject-dialog
            ref="rejectDialog"
            :visible.sync="rejectDialog"
            placeholder="请输入拒绝原因"
            :reason-detail="reasonDetail"
            :maxlength="100"
            @confirm="handleVerify(task_no, -1, $event)"
        />
    </div>
</template>

<script>
import { back } from '@/mixin/back';
import RejectDialog from "@/components/dialog/reject-dialog";

export default {
    name: 'ShopTaskVerifyList',
    mixins: [back],
    components: {RejectDialog},
    data() {
        return {
            filterData: {
                task_keyword: '',
                company_keyword: '',
                verify: 99,
                admin_true_name: '',
                start_time: '',
                end_time: ''
            },
            dateTimeRange: [],
            tableData: [],
            tableLoading: false,
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 20
            },
            authResult: {},
            statusList: [
                // 0:未提交 1:待审核,2审核通过,-1:不通过
                {label: '全部', value: 99},
                {label: '未提交', value: 0},
                {label: '待审核', value: 1},
                {label: '已通过', value: 2},
                {label: '未通过', value: -1},
            ],
            // 审核的任务编号
            task_no: '',
            rejectDialog: false,
            reasonDetail: ''
        };
    },
    computed: {},
    watch: {
        dateTimeRange(value) {
            this.filterData.start_time = value ? value[0] / 1000 : '';
            this.filterData.end_time = value ? value[1] / 1000 : '';
            this.getTableData(1);
        }
    },
    filters: {
        statusFilter(val) {
            switch (val) {
                case 0:
                    return '未提交';
                case 1:
                    return '待审核';
                case 2:
                    return '已通过';
                case -1:
                    return '未通过';
                default:
                    return '--';
            }
        }
    },
    mounted() {
        this.$store.commit('SET_HEADER', [{title: "APP后台"}, {title: '工作'}, {title: '商家远程任务'}, {title: '商家任务审核'}]);
        this.authResult = this.$route.meta.authResult;
        this.getTableData();
    },

    methods: {
        /**
         * @description 获取列表数据
         * @param page
         */
        getTableData(page) {
            this.tableLoading = true;
            let params = { ...this.filterData };

            params.page_id = page || this.page.now_page;
            this.$post('/student/task_stuagent_for_shop%5Caudit_list', params, res => {
                if (res.code === 1) {
                    this.tableData = res.data.list;
                    this.page = res.data.page;
                } else {
                    this.$notify({
                        title: '提示',
                        message: res.msg,
                        type: 'warning'
                    });
                }
                this.tableLoading = false;
            });
        },

        /**
         * 路由跳转
         * @param routeName
         * @param query
         */
        handleRoute(routeName, query) {
            this.$router.push({
                name: routeName,
                query
            });
        },

        /**
         * @description 过滤函数
         */
        emptyFormatter(row, column, val) {
            if (!val) return '--';
            return val;
        },

        /**
         * 显示审核操作弹窗
         * @param action -1拒绝 1 通过
         * @param row
         */
        showVerifyDialog(action, row) {
            this.task_no = row.task_no;
            // 通过
            if (action === 2) {
                this.$confirm('确认通过该任务审核?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.handleVerify(this.task_no, action);
                });
            } else {
                this.rejectDialog = true;
            }
        },

        /**
         * 审核
         * @param task_no
         * @param verify
         * @param verify_fail_reason
         */
        handleVerify(task_no, verify, verify_fail_reason) {
            if(!this.authResult.auth_verify) {
                this.$notify({
                    title: '提示',
                    message: '请联系管理员添加权限',
                    type: 'warning',
                    duration: 2000
                });
                return false;
            }
            let params = {
                task_no,
                verify,
                verify_fail_reason
            };

            this.$post('/student/task_stuagent_for_shop%5Caudit', params, resp => {
                if (resp.code === 1) {
                    this.$notify({
                        title: '提示',
                        message: '操作成功',
                        duration: 2000,
                        type: 'success'
                    });
                    this.getTableData();
                } else {
                    this.$notify({
                        title: '提示',
                        message: resp.msg,
                        duration: 2000,
                        type: 'warning'
                    });
                }
            });
        },

        /**
         * 回显完成和未完成原因
         * @param row
         */
        showReason(row) {
            this.reasonDetail = row.verify_fail_reason;
            this.rejectDialog = true;
        },
    }
};
</script>

<style lang="less" scoped>
.wrapper {
    width: 100%;

    .content-wrapper {
        display: flex;
        height: calc(100% - 24px);
        flex-direction: column;
        position: relative;
        margin: 12px;
        background: #fff;
        box-sizing: border-box;

        /*header*/

        .header {
            height: 68px;
            padding: 24px;
            box-sizing: border-box;
            box-shadow: 0px -1px 0px 0px #F0F2F5;
            display: flex;
            align-items: center;
            justify-content: space-between;
            border-bottom: 1px solid #F0F2F5;

            .header-title {
                color: #333333;
                font-size: 20px;
                height: 20px;
                font-weight: 500;
                position: relative;
                margin: 24px 0 24px 12px;

                &::before {
                    content: '';
                    position: absolute;
                    left: -8px;
                    top: -1px;
                    width: 3px;
                    height: 20px;
                    background: #1890FF;
                }
            }
        }

        /*筛选*/

        .filter-view {
            box-sizing: border-box;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            padding: 0 24px;
            margin-top: 12px;

            .header-new-box {
                display: flex;
                align-items: center;
                font-family: PingFangSC-Regular, PingFang SC;
                font-weight: 400;
                color: #333333;
                white-space: nowrap;
                margin-right: 24px;
                margin-bottom: 12px;

                &-title {
                    margin-right: 16px;
                    white-space: nowrap;
                }
            }
        }

        // 表格
        .table-wrapper {
            padding: 0 24px;
            flex: 1;
            height: 0;
            .cell-title {
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
                margin-bottom: 12px;
                display: -webkit-box;
                -webkit-box-orient: vertical;
                overflow: hidden;
                -webkit-line-clamp: 2;
            }
            .cell-content {
                display: -webkit-box;
                -webkit-box-orient: vertical;
                overflow: hidden;
                -webkit-line-clamp: 3;
            }
            .cell-tips {
                color: #999;
            }
        }

        .status-wrapper {
            display: flex;
            align-items: center;
            justify-content: center;

            .status-dot {
                width: 6px;
                height: 6px;
                border-radius: 50%;
                margin-right: 5px;

                &.success {
                    background: #4CD964;
                }

                &.danger {
                    background: #FF3030;
                }

                &.warning {
                    background: #FFA72D;
                }

                &.normal {
                    background: #A6A6A6;
                }
            }
        }

        /* 分页 */

        .pagination-wrapper {
            padding: 12px 24px;
            .el-pagination {
                float: right;
                padding: 0;
                background-color: transparent;
            }
        }
    }
    /deep/ .el-dialog__header {
        padding-top: 10px;
        box-shadow:0 1px 0 0 rgba(233,233,233,1);
        display: flex;
        align-items: center;
        background: #FAFAFA;
        border-radius: 4px 4px 0 0;
        .el-dialog__title {
            font-weight: 500;
            color: #333;
            font-size: 14px;
        }
        .el-icon-close:before {
            color: rgb(194,194,194);
            font-size: 17px;
            font-weight: bold;
        }
        .el-dialog__headerbtn {
            top: 14px;
        }
    }
    /deep/ .el-textarea__inner {
        resize: none;
    }
    /deep/ .el-table__fixed-right {
        right: 6px!important;
    }
    .data-table {
        ::-webkit-scrollbar {
            width: 6px;
            height: 6px;
        }
        // 操作按钮
        .option-btn-group {
            .el-button {
                margin-left: 0;
                margin-right: 10px;
            }
        }
    }
}
</style>
